package com.android.allwinner.aw360;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

/**
 * Created by xiasj on 17-7-13.
 */

public class CommandReceiver extends BroadcastReceiver {
    private static final String TAG = CommandReceiver.class.getSimpleName();
    private AW360Camera mCamera;

    public CommandReceiver(AW360Camera camera) {
        mCamera = camera;
    }

    public void releaseCamera() {
        mCamera = null;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (mCamera == null) {
            Log.e(TAG,"camera = null");
            return;
        }
        Log.d(TAG, "action=" + action);
        if (action.equals("android.aw360.test")) {
            int rval = -1;
            String string = null;
            int func = intent.getIntExtra("func", -1);
            int command = intent.getIntExtra("command", -1);
            int value = intent.getIntExtra("value", -1);
            String setString = intent.getStringExtra("string");
            Log.d(TAG, "aw360 func= " + func + " command=" + command + " value=" + value);
            switch (func) {
                case 0:
                    mCamera.setValue(command, value);
                    break;
                case 1:
                    rval = mCamera.getValue(command);
                    Log.d(TAG, "bv360GetVal=" + rval);
                    break;
                case 2:
                    string = mCamera.getString(command);
                    Log.d(TAG, "bv360GetStr =" + string);
                    break;
                case 3:
                    mCamera.setString(command, setString);
                    break;
                default:
                    break;
            }

        }


    }
}
